package com.cskaoyan.market.service.impl;

import com.cskaoyan.market.db.domain.MarketAddress;
import com.cskaoyan.market.db.domain.MarketAddressExample;
import com.cskaoyan.market.db.mapper.MarketAddressMapper;
import com.cskaoyan.market.service.AdminAddressService;
import com.github.pagehelper.PageHelper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AdminAddressServiceImpl implements AdminAddressService {

    @Autowired
    MarketAddressMapper mapper;

    @Override
    public List<MarketAddress> list(Integer page, Integer limit, String sort, String order, String name, Integer userId) {
        MarketAddressExample marketAddressExample = new MarketAddressExample();
        MarketAddressExample.Criteria criteria = marketAddressExample.createCriteria();
        if(!StringUtils.isEmpty(name))
            criteria.andNameEqualTo("%" + name + "%");
        if(userId != null) {
            criteria.andUserIdEqualTo(userId);
        }
        marketAddressExample.setOrderByClause(sort + " " + order);
        PageHelper.startPage(page,limit);
        List<MarketAddress> marketAddresses = mapper.selectByExample(marketAddressExample);
        return marketAddresses;
    }
}
